package top.mable.rabbitmq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @author taffywen
 * @date 2022/7/24 21:32
 */

//@Configuration
public class BusinessARabbitMqConfig {

    @Bean
    public TopicExchange rabbitMqExchange(){
        return new TopicExchange("rabbitMqExchange",true,false);
    }

    @Bean
    public Queue businessAQueue(){
        // 给队列设置过期时间
        Map args = new HashMap<>();
        args.put("x-message-ttl",5000); // 一定是int，毫秒

        //设置消息过期后，进入的死信队列
        args.put("x-dead-letter-exchange","dead_direct_exchange");
        args.put("x-dead-letter-routing-key","dead-key");

        return new Queue("queueA",true,false,false,args);
    }

    @Bean
    public Binding businessABinding(){
        return BindingBuilder.bind(businessAQueue()).to(rabbitMqExchange()).with("queue.a");
    }
}
